﻿using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;
using Runda.CMS.Common.Utility;
using System.Collections.Generic;
using Telerik.WebControls;
using System;
using System.Collections;
using System.Configuration;

namespace Runda.CMS.Portal.ContractFollowUp
{
    public partial class InstrumentAjustExtra : BasePage
    {
        public Guid MaintainID
        {
            get
            {
                if (hiddenMaintainID.Value == string.Empty) return Guid.Empty;
                else return new Guid(hiddenMaintainID.Value);
            }
            set
            {
                hiddenMaintainID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                if (Request.QueryString["maintainID"] != null) {
                    MaintainID = new Guid(Request.QueryString["maintainID"]);
                    WsmMaintainBillEntity maintainEntity = new SystemBll().Get<WsmMaintainBillEntity>(MaintainID);
                    WsmTaskRegisterEntity registerEntity = new SystemBll().Get<WsmTaskRegisterEntity>(maintainEntity.RegisterID);
                    WsmInstrumentInfoEntity instrumentEntity = new SystemBll().Get<WsmInstrumentInfoEntity>(registerEntity.InstrumentID);
                    AjustRate.Text = instrumentEntity.AjustRate.ToString();
                    List<WsmInstrumentAdjustEntity> adjustEntitys = new SystemBll().GetAll<WsmInstrumentAdjustEntity>("and MaintainID='"+MaintainID.ToString()+"'");
                    if (adjustEntitys != null && adjustEntitys.Count > 0) { 
                        WsmInstrumentAdjustEntity entity = adjustEntitys[0];
                        PostAjustResult.SelectedValue = entity.PostAjustResult.ToString();
                        Receiver.Text = entity.Receiver;
                        ReceiverTel.Text = entity.ReceiverTel;
                        AjustResultCurrent.SelectedValue = entity.AjustResultCurrent.ToString();
                        RequireOriginalBill.SelectedValue = entity.RequireOriginalBill.ToString();
                        Comment.Text = entity.Comment;
                    }
                }
            }
        }
        protected void lnkbtnSaveAndClose_Click(object sender, EventArgs e)
        {
            SystemBll bll = new SystemBll();
            bll.Delete<WsmInstrumentAdjustEntity>(" and MaintainID='" + MaintainID.ToString() + "'");

            WsmInstrumentAdjustEntity entity = new WsmInstrumentAdjustEntity();
            entity.PostAjustResult = System.Convert.ToInt32(PostAjustResult.SelectedValue);
            entity.Receiver = Receiver.Text.Trim()  ;
            entity.ReceiverTel =  ReceiverTel.Text.Trim();
            entity.AjustResultCurrent = System.Convert.ToInt32(AjustResultCurrent.SelectedValue);
            entity.RequireOriginalBill = System.Convert.ToInt32(RequireOriginalBill.SelectedValue);
            entity.Comment = Comment.Text.Trim();
            entity.AdjustID = Guid.NewGuid();
            entity.MaintainID = MaintainID;
            ClientScript.RegisterStartupScript(this.GetType(), "save", "alert('保存成功');", true);
        }
    }
}
